﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LevelNumberLetter2 : MonoBehaviour
{
    public TextButton leftButton;
    public TextButton centerButton;
    public TextButton rightButton;
    public TextButton fourButton;
    private string targetStr = "++-=";
    private string targetStr2 = "++-=";
    public GameLevelItem gameLevelItem;
    // Start is called before the first frame update
    void Start()
    {
        leftButton.Init("/", () =>
        {
            ButtonPress(leftButton);
        });
        centerButton.Init("/", () =>
        {
            ButtonPress(centerButton);
        });
        rightButton.Init("/", () =>
        {
            ButtonPress(rightButton);
        });
        fourButton.Init("/", () =>
        {
            ButtonPress(fourButton  );
        });
    }

    private string GetNextOperateCode(string curStr)
    {
        string nextOperateCode = string.Empty;
        switch (curStr)
        {
            case "/":
                nextOperateCode = "%";
                break;
            case "%":
                nextOperateCode = "+";
                break;
            case "+":
                nextOperateCode = "-";
                break;
            case "-":
                nextOperateCode = "=";
                break;
            case "=":
                nextOperateCode = "/";
                break;
            default:
                nextOperateCode = "=";
                break;
        }

        return nextOperateCode;
    }

    private void ButtonPress(TextButton tb)
    {
        if (GameCtrl.Instance.curGameState == GameState.Play)
        {
            tb.text.text = GetNextOperateCode(tb.text.text);
            JudeResult();
        }
    }

    private void JudeResult()
    {
        string resultStr = string.Empty;
        resultStr += leftButton.text.text;
        resultStr += centerButton.text.text;
        resultStr += rightButton.text.text;
        resultStr += fourButton.text.text;
        if (resultStr.Equals(targetStr) || resultStr.Equals(targetStr2))
            gameLevelItem.TriggerResult(true);
    }

}
